<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>订单总数</th>
	<td>
		<select name="order_total_count_operator">
			<option value="">请选择..</option>
			<option value="=" <?if(isset($_GET['order_total_count_operator']) && $_GET['order_total_count_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if(isset($_GET['order_total_count_operator']) && $_GET['order_total_count_operator'] == '>=')echo "selected='selected'"?>>&gt;=</option>
			<option value="<=" <?if(isset($_GET['order_total_count_operator']) && $_GET['order_total_count_operator'] == '<=')echo "selected='selected'"?>>&lt;=</option>
		</select>
		<input type="text" name="order_total_count" value="<?=isset($_GET['order_total_count']) ? $_GET['order_total_count'] : ''?>" />	
	</td>
	<td colspan="2"></td>
</tr>
<tr>
	<th>订单总金额（CNY）</th>
	<td>
		<select name="order_total_amount_cny_operator">
			<option value="">请选择..</option>
			<option value="=" <?if(isset($_GET['order_total_amount_cny_operator']) && $_GET['order_total_amount_cny_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if(isset($_GET['order_total_amount_cny_operator']) && $_GET['order_total_amount_cny_operator'] == '>=')echo "selected='selected'"?>>&gt;=</option>
			<option value="<=" <?if(isset($_GET['order_total_amount_cny_operator']) && $_GET['order_total_amount_cny_operator'] == '<=')echo "selected='selected'"?>>&lt;=</option>
		</select>
		<input type="text" name="order_total_amount_cny" value="<?=isset($_GET['order_total_amount_cny']) ? $_GET['order_total_amount_cny'] : ''?>" />	
	</td>
	<td colspan="2"></td>
</tr>
<tr>
	<th>网站/店铺</th>
	<td>
		<select name="shop_id">
			<option value="">请选择</option>
			<?foreach ($shop as $s):?>
			<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && $_GET['shop_id']==$s['id']) echo "selected='selected'"?>><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
	<td colspan="2"></td>
</tr>
<tr>
	<td></td>
	<td>
		<input class="button" type="submit" value="查询" />
	</td>
	<td>
		<a href="<?=url('Datacenter::Marketing/CustomerListDownload', array('url_arr_json' => $url_arr_json))?>">
			<input type="button" class="button" value="导出列表"/>
		</a>
	</td>
	<td><span id="download_loading_img"></span></td>
</tr>
</table>
</form></fieldset>
<table width="100%" class="list_table" id="list">
	<tr>
		<th rowspan="2">客户ID</th>
		<th rowspan="2">邮箱</th>
		<th colspan="4">初次订单</th>
		<th rowspan="2">订单数</th>
		<th rowspan="2">订单总额 </th>
		<th rowspan="2">购买周期</th>
		<th rowspan="2">最近购买日期</th>
		<th rowspan="2">购买次数最多类别</th>
		<th rowspan="2">购买金额最多类别</th>
		<th rowspan="2">最后更新时间</th>
	</tr>
	<tr>
		<th>全名</th>
		<th>国家</th>
		<th>时间</th>
		<th>渠道</th>
	</tr>
<?foreach ($customer as $c):?>
<tr>
	<th><?=$c['id']?></th>
	<td><a href="<?=url('Sales::Order/List', array('email' => $c['email'], 'is_search' => '1'))?>" ><?=$c['email']?></a></td>
	<td><?=$c['first_order_full_name']?></td>
	<td><?=$c['first_order_country_cn']?></td>
	<td><?=date('Y-m-d', strtotime($c['first_order_time']))?></td>
	<td><?=$c['shop_name']?></td>
	<td><?=$c['order_total_count']?></td>
	<td><?="￥" . number_format($c['order_total_amount_cny'])?></td>
	<td><?=$c['order_cycle']?></td>
	<td><?=date('Y-m-d', strtotime($c['last_order_time']))?></td>
	<td><?=implode(">", Product_categories::getAncestorNameById($c['order_count_top_categories_id']))?></td>
	<td><?=implode(">", Product_categories::getAncestorNameById($c['order_amount_top_categories_id']))?></td>
	<td><?=$c['update_time']?></td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<?php $this->_endblock();?>